/**
* @description: 周赛307 t1
* @author hewei
* @date 2022/8/21 10:32
* @version 1.0
*/

public class MinNumberOfHours {

    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int a = 0;
        int b = experience[0];
        for (int i : energy) {
            a += i;
        }
        a++;
        int sum = experience[0];
        for (int i = 1; i < experience.length; i++) {
            b = Math.max(b, experience[i] - sum);
            sum += experience[i];
        }
        b++;
        return Math.max(0, a - initialEnergy) + Math.max(0, b - initialExperience);
    }
}
